#!/usr/bin/env python
#coding=utf-8

import os
import logging

'''
Prefix Naming Convention:
    d_: deploy related functions
'''

def show_fun_message(fun):
    def v(*args):
        print '-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~'
        print 'Execute function: '+fun.__name__
        print fun.__doc__
        return fun(*args)
    return v

@show_fun_message
def d_update_version():
    '''
    Update VERSION under project root path. 
    '''
    current_dir_path = os.path.dirname(__file__)
    # delete VERSION
    file_version_path = current_dir_path+os.path.sep+'VERSION'
    if os.path.exists(file_version_path):
        os.remove(file_version_path)
        
    # check .svn/entries
    file_entries_path = current_dir_path+os.path.sep+'.svn'+os.path.sep+'entries'
    if os.path.exists(file_entries_path):
        h = open(file_entries_path, 'r')
        h.readline()
        h.readline()
        h.readline()
        rev_number = h.readline().strip('\n')
        h.close()
        h = open(file_version_path, 'wb')
        h.write(rev_number)
        h.close()

if __name__ == '__main__':
    # update VERSION
    d_update_version()
    print '-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~-*~'